package com.qingchunlin.blogsystem.common.enums;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum BusinessStatus {
    SUCCESS(1, "业务处理成功"),
    FAILURE(-1, "业务处理失败"),
    UNAUTHORIZED(-2, "用户未登录");

    private final Integer code;
    private final String message;

    public static BusinessStatus getBusinessStatusByCode(Integer code) {
        for (BusinessStatus businessStatus : BusinessStatus.values()) {
            if (businessStatus.getCode().equals(code)) {
                return  businessStatus;
            }
        }

        throw new IllegalArgumentException("无效的状态码: " + code);
    }
}
